package com.lwy.springboot2.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lwy.springboot2.common.Result;
import com.lwy.springboot2.entity.Admin;
import com.lwy.springboot2.mapper.AdminMapper;
import com.lwy.springboot2.service.AdminService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin")
@CrossOrigin(origins = "http://localhost:8080",allowCredentials = "true")
public class AdminController {

    @Resource
    private AdminMapper adminMapper;

    @Resource
    private AdminService adminService;


    @PostMapping("/login")
    public Result<?> login(@RequestBody Admin admin){
        System.out.println(admin);
        Admin one = adminMapper.selectOne(Wrappers.<Admin>lambdaQuery().eq(Admin::getUsername, admin.getUsername()).eq(Admin::getPassword, admin.getPassword()));
        if (one == null){
            return Result.error("-1","用户名或密码错误");
        }else {
            adminService.login(admin);
            return Result.success();
        }
    }
}
